import {
  BASE_URL,
  TIME_OUT
} from '../constant/constant'

class HYRequest {
  request(url, method, data) {
    return new Promise((resolve, reject) => {
      uni.request({
        url: BASE_URL + url,
        method,
        data,
        timeout: TIME_OUT,
        success(res) {
          resolve(res.data)
        },
        fail(err) {
          reject(err)
        }
      })
    })
  }

  get(url, data = {}) {
    return this.request(url, 'GET', data)
  }

  post(url, data = {}) {
    return this.request(url, 'POST', data)
  }
}

export default new HYRequest()